package cn.itcast.order.pojo;

/**
 * @author danDong
 * @date 2025-03-25 16:35:09
 */
public class OptionalExample {
    public static void main(String[] args) {
    }

    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode listNode = new ListNode();
        int val;
        int val2;
        ListNode next;
        ListNode next2;
        try {
            val = l1.val;
        } catch (Exception e) {
            val = 0;
        }

        try {
            val2 = l2.val;
        } catch (Exception e) {
            val2 = 0;
        }

        int add = val + val2;
        if (add >= 10) {
            add = add - 10;
            l1.next.val += 1;
        }
        listNode.val = add;
        if (!(l1.next == null && l2.next == null)) {
            try {
                next = l1.next;
            }catch (Exception e){
                next = null;
            }
            try{
                next2 = l2.next;
            }catch (Exception e){
                next2 = null;
            }
            listNode.next = addTwoNumbers(next, next2);
        }
        return listNode;
    }
}
